WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
landmark_base.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21// Wolf includes
22#include "core/common/wolf.h"
26
27// yaml
28#include "yaml-schema-cpp/yaml_server.hpp"
29
30namespace wolf
31{
32/*
33 * Macro for defining Autoconf landmark creator.
34 *
35 * Place a call to this macro inside your class declaration (in the landmark_class.h file),
36 * preferably just after the constructors. Inside 'public' keyword.
37 *
38 * In order to use this macro, the derived landmark class, LandmarkClass,
39 * must have two constructors available with the API:
40 *
41 * LandmarkClass(const YAML::Node& _node);
42 *
43 * Also, there should be the schema file 'LandmarkClass.schema' containing the specifications
44 * of the user input yaml file.
45 *
46 * NOTE: We use `new` and not `make_shared` since the constructor may (should) be private/protected
47 */
48#define WOLF_LANDMARK_CREATE(LandmarkClass) \
49 static LandmarkBasePtr create(const YAML::Node& _node, const std::vector<std::string>& _folders_schema = {}) \
50 { \
51 if (not _folders_schema.empty()) \
52 { \
53 auto server = yaml_schema_cpp::YamlServer(_folders_schema); \
54 server.setYaml(_node); \
55 if (not server.applySchema(#LandmarkClass)) \
56 { \
57 WOLF_ERROR(server.getLog()); \
58 return nullptr; \
59 } \
60 std::shared_ptr<LandmarkClass> lmk(new LandmarkClass(server.getNode())); \
61 lmk->emplacePriors(); \
62 return lmk; \
63 } \
64 std::shared_ptr<LandmarkClass> lmk(new LandmarkClass(_node)); \
65 lmk->emplacePriors(); \
66 return lmk; \
67 }
68
69#define WOLF_LANDMARK_TEMPLATE_DIM_CREATE(LandmarkClass, Dim) \
70 static LandmarkBasePtr create(const YAML::Node& _node, const std::vector<std::string>& _folders_schema = {}) \
71 { \
72 if (not _folders_schema.empty()) \
73 { \
74 auto server = yaml_schema_cpp::YamlServer(_folders_schema); \
75 server.setYaml(_node); \
76 if (not server.applySchema(#LandmarkClass + std::to_string(Dim) + "d")) \
77 { \
78 WOLF_ERROR(server.getLog()); \
79 return nullptr; \
80 } \
81 std::shared_ptr<LandmarkClass<Dim>> lmk(new LandmarkClass<Dim>(server.getNode())); \
82 lmk->emplacePriors(); \
83 return lmk; \
84 } \
85 std::shared_ptr<LandmarkClass<Dim>> lmk(new LandmarkClass<Dim>(_node)); \
86 lmk->emplacePriors(); \
87 return lmk; \
88 }
89
93{
94 friend FactorBase;
95
96 private:
97 MapBaseWPtr map_ptr_;
98 static unsigned int landmark_id_count_;
99
100 protected:
101 unsigned int landmark_id_;
102 unsigned int track_id_;
106
107 // Navigate wolf tree
108 void setProblem(ProblemPtr _problem) override;
109
110 public:
124 LandmarkBase(const std::string& _type,
125 const TypeComposite& _state_types,
126 const VectorComposite& _state_vectors,
127 const PriorComposite& _state_priors,
128 const int _external_id = -1,
129 const int _external_type = -1);
130
139 LandmarkBase(const std::string& _type, const TypeComposite& _state_types, const YAML::Node& _n);
140
141 ~LandmarkBase() override = default;
142 void remove(bool viral_remove_parent_without_children = false) override;
143
144 YAML::Node toYaml() const override;
145
146 // Properties
147 unsigned int id() const override;
148
151 void setId(unsigned int _id);
152
155 unsigned int trackId();
156
159 void setTrackId(unsigned int _track_id);
160
163 void setExternalId(const int& _external_id);
164
167 int getExternalId() const;
168
171 void setExternalType(const int& _external_type);
172
175 int getExternalType() const;
176
179 MapBaseConstPtr getMap() const;
180
183 MapBasePtr getMap();
184
187 void link(MapBasePtr);
188
191 template <typename classType, typename... T>
192 static std::shared_ptr<classType> emplace(MapBasePtr _map_ptr, T&&... all);
193
196 virtual void printHeader(int depth, //
197 bool factored_by, //
198 bool metric, //
199 bool state_blocks,
200 std::ostream& stream,
201 std::string _tabs = "") const;
202
205 virtual void print(int depth, //
206 bool factored_by, //
207 bool metric, //
208 bool state_blocks,
209 std::ostream& stream = std::cout,
210 std::string _tabs = "") const;
211
214 virtual CheckLog localCheck(bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
215
218 virtual bool check(CheckLog& _log, bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
219
220 private:
223 void setMap(const MapBasePtr _map_ptr);
224
225 public:
228 LandmarkBasePtr shared_from_this_landmark();
229
232 LandmarkBaseConstPtr shared_from_this_landmark() const;
233};
234} // namespace wolf
235
236#include "core/map/map_base.h"
239
240namespace wolf
241{
242template <typename classType, typename... T>
243std::shared_ptr<classType> LandmarkBase::emplace(MapBasePtr _map_ptr, T&&... all)
244{
245 std::shared_ptr<classType> lmk = std::make_shared<classType>(std::forward<T>(all)...);
246 lmk->emplacePriors();
247 lmk->link(_map_ptr);
248 return lmk;
249}
250
251inline MapBaseConstPtr LandmarkBase::getMap() const
252{
253 return map_ptr_.lock();
254}
255
256inline MapBasePtr LandmarkBase::getMap()
257{
258 return map_ptr_.lock();
259}
260
261inline void LandmarkBase::setMap(const MapBasePtr _map_ptr)
262{
263 map_ptr_ = _map_ptr;
264}
265
266inline unsigned int LandmarkBase::id() const
267{
268 return landmark_id_;
269}
270
271inline void LandmarkBase::setId(unsigned int _id)
272{
273 landmark_id_ = _id;
274 if (_id > landmark_id_count_) landmark_id_count_ = _id;
275}
276
277inline unsigned int LandmarkBase::trackId()
278{
279 return track_id_;
280}
281
282inline void LandmarkBase::setTrackId(unsigned int _track_id)
283{
284 track_id_ = _track_id;
285}
286
287inline void LandmarkBase::setExternalId(const int& _external_id)
288{
289 external_id_ = _external_id;
290}
291
293{
294 return external_id_;
295}
296
297inline void LandmarkBase::setExternalType(const int& _external_type)
298{
299 external_type_ = _external_type;
300}
301
303{
304 return external_type_;
305}
306
308{
309 return std::static_pointer_cast<LandmarkBase>(shared_from_this());
310}
311
312inline LandmarkBaseConstPtr LandmarkBase::shared_from_this_landmark() const
313{
314 return std::static_pointer_cast<const LandmarkBase>(shared_from_this());
315}
316
317} // namespace wolf
Log of a consistency check: whether it is consistent and the explanation of the inconsistencies.
Definition: check_log.h:30
Base class of factors: a constraint between state blocks of one or more nodes, given a measurement an...
Definition: factor_base.h:73
Base class of landmarks: elements of the map with state blocks, observed from the frames.
Definition: landmark_base.h:93
void setProblem(ProblemPtr _problem) override
Sets the problem (if not set yet) and notifies it of all the state blocks and prior factors.
Definition: landmark_base.cpp:107
int getExternalId() const
Returns the id provided by an external tracker (-1 untracked)
Definition: landmark_base.h:292
unsigned int track_id_
Associated track id.
Definition: landmark_base.h:102
int external_type_
Type provided by an external classifier (-1 unclassified)
Definition: landmark_base.h:104
int external_id_
Id provided by an external tracker (-1 untracked)
Definition: landmark_base.h:103
void setTrackId(unsigned int _track_id)
Sets the associated track id.
Definition: landmark_base.h:282
unsigned int id() const override
Returns the id of the node, unique among the nodes of its category.
Definition: landmark_base.h:266
LandmarkBase(const std::string &_type, const TypeComposite &_state_types, const VectorComposite &_state_vectors, const PriorComposite &_state_priors, const int _external_id=-1, const int _external_type=-1)
Constructor from the type and the state specs composites (types, vectors, priors)
Definition: landmark_base.cpp:28
virtual void print(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream=std::cout, std::string _tabs="") const
Prints this node and, depending on the depth, its children.
Definition: landmark_base.cpp:133
MapBaseConstPtr getMap() const
Returns the map the landmark belongs to.
Definition: landmark_base.h:251
int getExternalType() const
Returns the type provided by an external classifier (-1 unclassified)
Definition: landmark_base.h:302
unsigned int landmark_id_
Landmark id, unique among landmarks.
Definition: landmark_base.h:101
YAML::Node toYaml() const override
Returns a YAML node with the type, the states and their priors.
Definition: landmark_base.cpp:77
virtual void printHeader(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream, std::string _tabs="") const
Prints the information of this node (not of its children)
Definition: landmark_base.cpp:114
void setExternalType(const int &_external_type)
Sets the type provided by an external classifier.
Definition: landmark_base.h:297
void remove(bool viral_remove_parent_without_children=false) override
Removes the node: its state blocks and the factors constraining them.
Definition: landmark_base.cpp:57
LandmarkBasePtr shared_from_this_landmark()
Returns a shared pointer to this landmark.
Definition: landmark_base.h:307
virtual bool check(CheckLog &_log, bool _verbose, std::ostream &_stream, std::string _tabs="") const
Checks the consistency of this node and its children, composing the log.
Definition: landmark_base.cpp:174
virtual CheckLog localCheck(bool _verbose, std::ostream &_stream, std::string _tabs="") const
Checks the consistency of this node (not of its children)
Definition: landmark_base.cpp:143
TimeStamp stamp_
Time stamp of the creation of the landmark (unused)
Definition: landmark_base.h:105
void link(MapBasePtr)
Links the landmark to a map.
Definition: landmark_base.cpp:90
void setId(unsigned int _id)
Sets the landmark id, updating the counter to avoid repeated ids.
Definition: landmark_base.h:271
~LandmarkBase() override=default
unsigned int trackId()
Returns the associated track id.
Definition: landmark_base.h:277
void setExternalId(const int &_external_id)
Sets the id provided by an external tracker.
Definition: landmark_base.h:287
static std::shared_ptr< classType > emplace(MapBasePtr _map_ptr, T &&... all)
Creates a landmark of class classType, emplaces its priors and links it to the map.
Definition: landmark_base.h:243
Base class of the nodes having state blocks (sensors, frames, captures and landmarks)
Definition: node_state_blocks.h:36
TimeStamp implements basic functionalities for time stamps.
Definition: time_stamp.h:39
Composite of state vectors.
Definition: vector_composite.h:29
Definition: capture_base.h:23